package com.haixiaoke.saas.callback;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.haixiaoke.saas.bill.service.IHouseBillService;
import com.haixiaoke.saas.system.framework.manager.AsyncManager;
import com.haixiaoke.saas.system.framework.manager.factory.AsyncFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @author qixi
 * @date 2024/6/28
 */
@RestController
@RequestMapping("/callback/yima")
@Slf4j
public class YimaCallBackController {

    @Autowired
    private IHouseBillService houseBillService;


    @PostMapping("/payCallback")
    public String callback(@RequestBody Map<String, Object> map) {
        log.info("收到翼码回调请求：{}", map);
        String status = ObjectUtil.toString(map.get("status"));
        if (StrUtil.equals(status, "1")) {
            // 异步处理
            AsyncManager.me().execute(AsyncFactory.yiMaCallbackHouseBillPay(map));
        } else {
            log.error("翼码回调支付失败：{}", map);
        }
        return "success";
    }
}
